<?php
$this->title = "Requests";
$this->headTitle($this->title);
?>	
		
		<div id="requests_inside" class="content">
		<div id="received requests">
			<p>Received friend requests:</p>
			<table title="received requests" id="hor-minimalist-a">
			<?php $count = 0; ?>
				<tr>
					<th>&nbsp;</th>
					<th>First name</th>
					<th>Last name</th>
					<th>Username</th>
					<th>Gender</th>
					<th>&nbsp;</th>
					<th>&nbsp;</th>
				</tr>
			<?php foreach($this->receivedRequests as $friends) : ?>
				<tr>
					<td><?php $count = $count+1;
							echo $this->escape($count);	 ?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['User_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$fname = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($fname['FirstName'] != null)
							{ echo $this->escape($fname['FirstName']); }
							else echo $this->escape("-Not set by user-");
						}
						else echo $this->escape("-Not set by user-");?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['User_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$lname = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($lname['LastName'] != null)
							{ echo $this->escape($lname['LastName']); }
							else echo $this->escape("-Not set-");
						}
						else echo $this->escape("-Not set-");?>
					</td>
					<td>
						<?php $user = $this->users->getUser((int)$friends['User_id']);
						echo $this->escape($user['Username']);?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['User_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$gender = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($gender['Gender'] != null)
							{	if ($gender['Gender'] == '1')
									echo $this->escape("Male"); 
								else if ($gender['Gender'] == '2')
								echo $this->escape("Female");
							}
							else echo $this->escape("-Not set-");
						}
						else echo $this->escape("-Not set-");?>
					</td>
					<td>
						<a href="<?php  echo $this->url(array('controller'=>'Friends','action'=>'accept', 'sender'=>(int)$friends->User_id, 'receiver'=>(int)$friends->Friend_id ));?>">Accept</a>
					</td>
					<td>
						<a href="<?php  echo $this->url(array('controller'=>'Friends','action'=>'reject', 'req_id'=>(int)$friends->id));?>">Reject</a>
					</td>
				</tr>
			<?php endforeach; ?>
			</table>
		</div>
		
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		
		<div id="Sent requests">
			<p>Pending sent friend requests:</p>
			<table title="Sent requests" id="hor-minimalist-g">
			<?php $count = 0; ?>
				<tr>
					<th>&nbsp;</th>
					<th>First name</th>
					<th>Last name</th>
					<th>Username</th>
					<th>Gender</th>
					<th>&nbsp;</th>
				</tr>
			<?php foreach($this->sentRequests as $friends) : ?>
				<tr>
					<td><?php $count = $count+1;
							echo $this->escape($count);	 ?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['Friend_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$fname = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($fname['FirstName'] != null)
							{ echo $this->escape($fname['FirstName']); }
							else echo $this->escape("-Not set by user-");
						}
						else echo $this->escape("-Not set by user-");?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['Friend_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$lname = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($lname['LastName'] != null)
							{ echo $this->escape($lname['LastName']); }
							else echo $this->escape("-Not set by user-");
						}
						else echo $this->escape("-Not set by user-");?>
					</td>
					<td>
						<?php $user = $this->users->getUser((int)$friends['Friend_id']);
						echo $this->escape($user['Username']);?>
					</td>
					<td>
						<?php 
						$user = $this->users->getUser((int)$friends['Friend_id']);
						$bool = $this->basicinfo->existsBasicInfo($user['id']);
						if($bool == 1)
						{
							$gender = $this->basicinfo->getBasicInfo( (int)$user['id']);
							if ($gender['Gender'] != null)
							{	if ($gender['Gender'] == '1')
									echo $this->escape("Male"); 
								else if ($gender['Gender'] == '2')
								echo $this->escape("Female");
							}
							else echo $this->escape("-Not set by user-");
						}
						else echo $this->escape("-Not set by user-");?>
					</td>
					<td>
						<a href="<?php echo $this->url(array('controller'=>'Friends','action'=>'reject', 'req_id'=>(int)$friends->id));?>">Cancel request</a>
					</td>

				</tr>
			<?php endforeach; ?>
			</table>
			
			</div>
		
		</div>
		